<?php
class AjaxAction extends Action {

    public function category(){

		if(IS_POST){
			$pid = (int)$_POST['pid'];
			if($pid<=0) {
				$html = '<select id="typeid" class="inp inw" style="width:105px;" name="typeid">';
				$html.= '<option value="">选择子分类</option>';
				$html.= '</select>';
				$this->ajaxReturn($html,'success',1);
				
			}
			$Category =   M('Category');
			$condition['parentid'] = $pid;
			$CateArr = $Category->field('catname,catid')->where($condition)->select(); 
			
			if($CateArr){
				$html = '<select id="typeid" class="inp inw" style="width:105px;" name="typeid">';
				foreach($CateArr as $Cate) {
					$html.= '<option value="'.$Cate['catid'].'">'.$Cate['catname'].'</option>';
				}
				$html.= '</select>';
			}
			$this->ajaxReturn($html,'success',1);
			

			
		}

		exit;
    }

	public function area(){

		if(IS_POST){
			$pid = (int)$_POST['pid'];
			if($pid<=0) {
				$html = '<select id="city" class="inp inw" style="width:100px;" name="city">';
				$html.= '<option value="">请选县区</option>';
				$html.= '</select>';
				$this->ajaxReturn($html,'success',1);
				
			}
			$Area =   M('Area');
			$condition['parentid'] = $pid;
			$CateArr = $Area->field('name,id')->where($condition)->select(); 
			if($CateArr){
				$html = '<select id="city" class="inp inw" style="width:100px;" name="city">';
				foreach($CateArr as $Cate) {
					$html.= '<option value="'.$Cate['id'].'">'.$Cate['name'].'</option>';
				}
				$html.= '</select>';
				$this->ajaxReturn($html,'success',1);
			}
			
		}

		exit;
    }

}